package com.nuaa.dao.overseas.impl;

import java.io.File;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.stereotype.Repository;

import com.nuaa.dao.base.impl.BaseDaoImpl;
import com.nuaa.dao.overseas.inter.BackSupDaoInter;
import com.nuaa.domain.overseas.BackSupEntity;
@Repository("backSupDao")
public class BackSupDaoImpl extends BaseDaoImpl<BackSupEntity, Integer> implements BackSupDaoInter{
	@Transactional
	@Override
	public boolean delByOrderNo(String orderNo) {
		StringBuilder sql=new StringBuilder();
		sql.append("select * from back_sup where order_no = '");
		sql.append(orderNo);
		sql.append("'");
		List<BackSupEntity> list = this.search(BackSupEntity.class, sql.toString());
		if(list.size()==0)
			return false;
		BackSupEntity entity = list.get(0);
		String dir = System.getProperty("webApp.path")+"file";
		System.out.println(dir);
		if(!"".equals(entity.getBack_logis_tb())){
			File file = new File(dir+"\\"+entity.getBack_logis_tb());
			if(file.exists()){
				file.delete();
			}
		}
		if(!"".equals(entity.getBack_num_detail_tb())){
			File file = new File(dir+"\\"+entity.getBack_num_detail_tb());
			if(file.exists()){
				file.delete();
			}
		}
		if(!"".equals(entity.getOther_file())){
			File file = new File(dir+"\\"+entity.getOther_file());
			if(file.exists()){
				file.delete();
			}
		}
		
//		StringBuffer sql2 = new StringBuffer();
//		sql.append("delete from back_sup where order_no ='");
//		sql.append(orderNo);
//		sql.append("'");
		try{
			//this.update(sql2.toString());
			this.delete(entity);
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		return true;
	}
	@Override
	public void delFileByName(String fileName) {
		String dir = System.getProperty("webApp.path")+"file";
		if(!"".equals(fileName)){
			File file = new File(dir+"\\"+fileName);
			if(file.exists()){
				file.delete();
			}
		}
		
	}
}
